import { Router } from 'express';
import authRoutes from './auth.routes.js';
import userRoutes from './user.routes.js';
import courseRoutes from './course.routes.js';
import enrollmentRoutes from './enrollment.routes.js';

const router = Router();

// API 版本前缀
const apiPrefix = '/v1';

// 健康检查路由
router.get(`${apiPrefix}/health`, (req, res) => {
  res.status(200).json({
    status: 'success',
    message: '服务器运行正常',
    timestamp: new Date().toISOString(),
    environment: process.env.NODE_ENV || 'development'
  });
});

// 认证相关路由
router.use(`${apiPrefix}/auth`, authRoutes);

// 用户相关路由
router.use(`${apiPrefix}/users`, userRoutes);

// 课程相关路由
router.use(`${apiPrefix}/courses`, courseRoutes);

// 选课相关路由
router.use(`${apiPrefix}/enrollments`, enrollmentRoutes);

// 404 处理
router.use((req, res) => {
  res.status(404).json({
    success: false,
    message: `未找到 ${req.originalUrl} 路由`
  });
});

export default router;
